package com.example;

import java.util.List;

/*
 *  @author 雨安
 *  类名： StreamDemo
 *  创建时间：2024/3/8
 */
public class StreamDemo {
    public static void main(String[] args) {

        List<Person> people = List.of(
                new Person("6", "1"),
                new Person("5", "2"),
                new Person("4", "3"),
                new Person("3", "4"),
                new Person("2", "5"),
                new Person("1", "6"));
        //流 必须有结束操作否则都不执行 ele -> System.out.println(ele)
        people.stream()
                .parallel() //这叫cpu线程多开
                .filter(ele -> ele.getA().equals("6")) //过滤 filter
                .map(ele -> {
                    System.out.println("当前执行的线程：" + Thread.currentThread());
                    ele.setB("吾儿李乐乐");
                    return ele;
                }) //替换操作
                .forEach(System.out::println); //遍历的意思

    }
}

class Person{
    private String a;

    private String b;

    public String getA() {
        return a;
    }

    public void setA(String a) {
        this.a = a;
    }

    public String getB() {
        return b;
    }

    public void setB(String b) {
        this.b = b;
    }

    public Person(String a, String b) {
        this.a = a;
        this.b = b;
    }

    public Person() {
        System.out.println("我是Person对象我被创建了");
    }

    @Override
    public String toString() {
        return "Person{" +
                "a='" + a + '\'' +
                ", b='" + b + '\'' +
                '}';
    }
}
